<template>
  <el-dialog
    title="视频播放"
    :visible.sync="dialogVisible"
    width="50%"
    :before-close="handleClose"
    center
  >
    <div class="video-container">
      <video
        v-if="videoUrl"
        :src="videoUrl"
        controls
        style="width: 100%"
        ref="videoPlayer"
      ></video>
    </div>
  </el-dialog>
</template>

<script>
export default {
  name: "PlayVideo",
  props: {
    visible: {
      type: Boolean,
      default: false,
    },
    videoUrl: {
      type: String,
      default: "",
    },
  },
  computed: {
    dialogVisible: {
      get() {
        return this.visible;
      },
      set(val) {
        this.$emit("update:visible", val);
      },
    },
  },
  methods: {
    handleClose() {
      if (this.$refs.videoPlayer) {
        this.$refs.videoPlayer.pause();
      }
      this.$emit("update:visible", false);
    },
  },
};
</script>

<style scoped>
.video-container {
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 300px;
}
</style>
